<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Robocup-denayer-project-a: read-only/trunk/source/motors.cpp Bron Bestand</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javaScript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Gegenereerd door Doxygen 1.7.1 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Zoeken');
--></script>
<script type="text/javascript">
function hasClass(ele,cls) {
  return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls) {
  if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls) {
  if (hasClass(ele,cls)) {
    var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
    ele.className=ele.className.replace(reg,' ');
  }
}

function toggleVisibility(linkObj) {
 var base = linkObj.getAttribute('id');
 var summary = document.getElementById(base + '-summary');
 var content = document.getElementById(base + '-content');
 var trigger = document.getElementById(base + '-trigger');
 if ( hasClass(linkObj,'closed') ) {
   summary.style.display = 'none';
   content.style.display = 'block';
   trigger.src = 'open.png';
   removeClass(linkObj,'closed');
   addClass(linkObj,'opened');
 } else if ( hasClass(linkObj,'opened') ) {
   summary.style.display = 'block';
   content.style.display = 'none';
   trigger.src = 'closed.png';
   removeClass(linkObj,'opened');
   addClass(linkObj,'closed');
 }
 return false;
}
</script>
<div class="navigation" id="top">
  <div class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Hoofd&nbsp;Pagina</span></a></li>
      <li><a href="annotated.html"><span>Klassen</span></a></li>
      <li class="current"><a href="files.html"><span>Bestanden</span></a></li>
      <li id="searchli">
        <div id="MSearchBox" class="MSearchBoxInactive">
          <span class="left">
            <form id="FSearchBox" action="search.php" method="get">
              <img id="MSearchSelect" src="search/mag.png" alt=""/>
              <input type="text" id="MSearchField" name="query" value="Zoeken" size="20" accesskey="S" 
                     onfocus="searchBox.OnSearchFieldFocus(true)" 
                     onblur="searchBox.OnSearchFieldFocus(false)"/>
            </form>
          </span><span class="right"></span>
        </div>
      </li>
    </ul>
  </div>
  <div class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&nbsp;Lijst</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<h1>read-only/trunk/source/motors.cpp</h1>  </div>
</div>
<div class="contents">
<a href="motors_8cpp.html">Ga naar de documentatie van dit bestand.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00009"></a>00009 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &lt;pthread.h&gt;</span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &quot;<a class="code" href="motors_8h.html">motors.h</a>&quot;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &quot;<a class="code" href="serial_8h.html">serial.h</a>&quot;</span>
<a name="l00013"></a>00013 
<a name="l00014"></a>00014 <span class="keyword">using namespace </span>std;
<a name="l00015"></a>00015 
<a name="l00024"></a><a class="code" href="class_motors.html#a9ce7e0a99f4a434a2e545d4634b10eec">00024</a> <a class="code" href="class_motors.html#a9ce7e0a99f4a434a2e545d4634b10eec" title="Constructor.">Motors::Motors</a>(<span class="keywordtype">int</span> prt,<span class="keywordtype">int</span> br)
<a name="l00025"></a>00025 {
<a name="l00026"></a>00026         cout &lt;&lt; <span class="stringliteral">&quot;Motor initialize...&quot;</span> &lt;&lt; endl;  
<a name="l00027"></a>00027 
<a name="l00028"></a>00028         poort=prt;
<a name="l00029"></a>00029         baudrate=br;
<a name="l00030"></a>00030 }
<a name="l00031"></a>00031 
<a name="l00040"></a><a class="code" href="class_motors.html#af669d235bb9ed93f6951bd256522ce51">00040</a> <a class="code" href="class_motors.html#af669d235bb9ed93f6951bd256522ce51" title="Destructor.">Motors:: ~Motors</a>(<span class="keywordtype">void</span>)
<a name="l00041"></a>00041 {
<a name="l00042"></a>00042         
<a name="l00043"></a>00043 }
<a name="l00044"></a>00044 
<a name="l00053"></a><a class="code" href="class_motors.html#ae5fe2fd03098baf0fd6e55c1b52a01e9">00053</a> <span class="keywordtype">void</span> <a class="code" href="class_motors.html#ae5fe2fd03098baf0fd6e55c1b52a01e9" title="setSpeed">Motors::setSpeed</a>(<span class="keywordtype">int</span> spd1,<span class="keywordtype">int</span> dir1,<span class="keywordtype">int</span> spd2,<span class="keywordtype">int</span> dir2)
<a name="l00054"></a>00054 {
<a name="l00055"></a>00055         <span class="keywordtype">int</span> res = <a class="code" href="serial_8cpp.html#afcbe0bdca93dd392b104bf7c7775ba42">OpenComport</a>(poort, baudrate);
<a name="l00056"></a>00056         <span class="keywordtype">float</span> speed1 = <a class="code" href="motors_8h.html#a5dd13af014b612f67220ddd841479c5b">MAXV</a>*spd1*0.01;
<a name="l00057"></a>00057         <span class="keywordtype">float</span> speed2 = <a class="code" href="motors_8h.html#a5dd13af014b612f67220ddd841479c5b">MAXV</a>*spd2*0.01;
<a name="l00058"></a>00058         <span class="keywordflow">if</span>(res == 1)
<a name="l00059"></a>00059         {
<a name="l00060"></a>00060                 printf(<span class="stringliteral">&quot;Error while opening comport\n&quot;</span>);
<a name="l00061"></a>00061                 <span class="keywordflow">return</span>;
<a name="l00062"></a>00062         }
<a name="l00063"></a>00063 
<a name="l00064"></a>00064         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[3];
<a name="l00065"></a>00065 
<a name="l00066"></a>00066         buf[0]=0xD0 | (dir2 * 4) | dir1;
<a name="l00067"></a>00067         buf[1] = speed1;                
<a name="l00068"></a>00068         buf[2] = speed2;
<a name="l00069"></a>00069         res = <a class="code" href="serial_8cpp.html#af2a032058a335a76ef91d025ac63942b">SendBuf</a>(poort, buf, 3);
<a name="l00070"></a>00070         <span class="keywordflow">if</span>(res != 1)
<a name="l00071"></a>00071         {
<a name="l00072"></a>00072                 <span class="keywordflow">if</span>(spd1 == 0 &amp;&amp; spd2 == 0)
<a name="l00073"></a>00073                         printf(<span class="stringliteral">&quot;Stopped\n&quot;</span>);
<a name="l00074"></a>00074                 <span class="keywordflow">else</span>
<a name="l00075"></a>00075                         printf(<span class="stringliteral">&quot;Going forward, speed %d %d\n&quot;</span>, (<span class="keywordtype">int</span>)speed1,(<span class="keywordtype">int</span>)speed2);
<a name="l00076"></a>00076         }
<a name="l00077"></a>00077         <span class="keywordflow">else</span>
<a name="l00078"></a>00078                 printf(<span class="stringliteral">&quot;Error while trying to move.\n&quot;</span>);
<a name="l00079"></a>00079         <a class="code" href="serial_8cpp.html#a76b8f1bd6cb72a1e153df998c2742842">CloseComport</a>(poort);
<a name="l00080"></a>00080 }
<a name="l00081"></a>00081 
<a name="l00090"></a><a class="code" href="class_motors.html#a8492da1f62dcd7034f93fc8441e6579a">00090</a> <span class="keywordtype">void</span> <a class="code" href="class_motors.html#a8492da1f62dcd7034f93fc8441e6579a" title="setSpeedAcc">Motors::setSpeedAcc</a>(<span class="keywordtype">int</span> spd1,<span class="keywordtype">int</span> dir1,<span class="keywordtype">int</span> spd2,<span class="keywordtype">int</span> dir2)
<a name="l00091"></a>00091 {
<a name="l00092"></a>00092         <span class="keywordtype">int</span> res = <a class="code" href="serial_8cpp.html#afcbe0bdca93dd392b104bf7c7775ba42">OpenComport</a>(poort, baudrate);
<a name="l00093"></a>00093         <span class="keywordtype">float</span> speed1 = <a class="code" href="motors_8h.html#a5dd13af014b612f67220ddd841479c5b">MAXV</a>*spd1*0.01;
<a name="l00094"></a>00094         <span class="keywordtype">float</span> speed2 = <a class="code" href="motors_8h.html#a5dd13af014b612f67220ddd841479c5b">MAXV</a>*spd2*0.01;
<a name="l00095"></a>00095         <span class="keywordflow">if</span>(res == 1)
<a name="l00096"></a>00096         {
<a name="l00097"></a>00097                 printf(<span class="stringliteral">&quot;Error while opening comport\n&quot;</span>);
<a name="l00098"></a>00098                 <span class="keywordflow">return</span>;
<a name="l00099"></a>00099         }
<a name="l00100"></a>00100 
<a name="l00101"></a>00101         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[3];
<a name="l00102"></a>00102 
<a name="l00103"></a>00103         buf[0]=0xE0 | (dir2 * 4) | dir1;
<a name="l00104"></a>00104         buf[1] = speed1;                
<a name="l00105"></a>00105         buf[2] = speed2;
<a name="l00106"></a>00106         res = <a class="code" href="serial_8cpp.html#af2a032058a335a76ef91d025ac63942b">SendBuf</a>(poort, buf, 3);
<a name="l00107"></a>00107         <span class="keywordflow">if</span>(res != 1)
<a name="l00108"></a>00108         {
<a name="l00109"></a>00109                 <span class="keywordflow">if</span>(spd1 == 0 &amp;&amp; spd2 == 0)
<a name="l00110"></a>00110                         printf(<span class="stringliteral">&quot;Stopped\n&quot;</span>);
<a name="l00111"></a>00111                 <span class="keywordflow">else</span>
<a name="l00112"></a>00112                         printf(<span class="stringliteral">&quot;Going forward, speed %d %d\n&quot;</span>, (<span class="keywordtype">int</span>)speed1,(<span class="keywordtype">int</span>)speed2);
<a name="l00113"></a>00113         }
<a name="l00114"></a>00114         <span class="keywordflow">else</span>
<a name="l00115"></a>00115                 printf(<span class="stringliteral">&quot;Error while trying to move.\n&quot;</span>);
<a name="l00116"></a>00116         <a class="code" href="serial_8cpp.html#a76b8f1bd6cb72a1e153df998c2742842">CloseComport</a>(poort);
<a name="l00117"></a>00117 }
<a name="l00118"></a>00118 
<a name="l00127"></a><a class="code" href="class_motors.html#a2a03135d58d03d8a82be9be0ceca1236">00127</a> <span class="keywordtype">void</span> <a class="code" href="class_motors.html#a2a03135d58d03d8a82be9be0ceca1236" title="stopMotors">Motors::stopMotors</a>(<span class="keywordtype">void</span>)
<a name="l00128"></a>00128 {
<a name="l00129"></a>00129         <a class="code" href="class_motors.html#ae5fe2fd03098baf0fd6e55c1b52a01e9" title="setSpeed">setSpeed</a>(0,<a class="code" href="motors_8h.html#adaa6428b3f3b92676ba73f27b1ed8035">MOTOR_BRAKE</a>,0,<a class="code" href="motors_8h.html#adaa6428b3f3b92676ba73f27b1ed8035">MOTOR_BRAKE</a>);
<a name="l00130"></a>00130 }
<a name="l00131"></a>00131 
<a name="l00140"></a><a class="code" href="class_motors.html#ae4afe9d4e852132186622c75dc829d6a">00140</a> <span class="keywordtype">void</span> <a class="code" href="class_motors.html#ae4afe9d4e852132186622c75dc829d6a" title="setParam">Motors::setParam</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> param,<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> value)
<a name="l00141"></a>00141 {
<a name="l00142"></a>00142         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>   cmd,params[COMLEN];
<a name="l00143"></a>00143         
<a name="l00144"></a>00144         cmd=0xAF;
<a name="l00145"></a>00145         params[0]=param;
<a name="l00146"></a>00146         params[1]=value;
<a name="l00147"></a>00147         params[2]=0x55;
<a name="l00148"></a>00148         params[3]=0x2A;
<a name="l00149"></a>00149         
<a name="l00150"></a>00150         <span class="comment">//ms-&gt;addCommand(cmd,params,5);</span>
<a name="l00151"></a>00151 }
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Gegenereerd op Do 19 Mei 2011 10:15:28 voor Robocup-denayer-project-a door&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.1 </small></address>
</body>
</html>
